/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package customer_cmds;

import appClientHandler.AUPCustomerLocal;
import appClientHandler.AUPCustomerLocal;
import appClientHandler.HandlerLocal;
import appClientHandler.LoginResult;
import commands.CommandAbstract;
import commands.ICommandContextuelle;
import context.IContext;
import dao.IdaoLocal;
import entities.Account;
import general.ConstantesConsole;
import general.OptionMutable;

import java.io.PrintStream;
import java.util.Iterator;
import java.util.List;
import javax.ejb.EJB;

/**
 *
 * eCOM - Adopte un Presta - Mars-Avril 2013
 * @author Kheira, Jef, William, Tuan-Long
 */
public class LoginCommand extends CommandAbstract implements ICommandContextuelle {
    
	private IContext context;
        @EJB
	private IdaoLocal daoJpa;


	public LoginCommand(IContext context, IdaoLocal daoJpa) 
        {		
		this.context = context;
		this.daoJpa = daoJpa;

		OptionMutable loginOption = new OptionMutable("user", false);
		loginOption.setIsRequired(true);

		OptionMutable passwordOption = new OptionMutable("password", false);
		passwordOption.setIsRequired(true);

		addOption(loginOption);
		addOption(passwordOption);
	}


        
        
	@Override
	public String getName() {
		return "login";
	}

	@Override
	public String getUsage() {
		return "login --user <login> --password <password>";
	}

	@Override
	public String getShortDescription() {
		return "Identification d'un client sur Adopte Un Presta.";
	}

	@Override
	public IContext getContext() {
		return context;
	}

	@Override
	public void setContext(IContext context) {
		this.context = context;
	}

	@Override
	protected void execute(PrintStream out, PrintStream err) {

		String login = this.getStringOption("user", null);
		String password = this.getStringOption("password", null);
                
                if (this.daoJpa == null) {
                    out.println("LoginCommand -- DAO nul...");
                }

                if (this.daoJpa != null) 
                {
                    Account client = this.daoJpa.getAccountByLoginAndPass(login, password);
                    
                    
                }
		

	}

}
